interface SuccessResponse<T = any> {
  success: true
  data: T
  message?: string
}

interface ErrorResponse {
  success: false
  error: string
  message?: string
}

interface PaginationInfo {
  page: number
  pageSize: number
  total: number
  totalPages: number
}

interface PaginatedResponse<T = any> {
  success: true
  data: T[]
  pagination: PaginationInfo
  message?: string
}

export function successResponse<T = any>(data: T, message?: string): SuccessResponse<T> {
  return {
    success: true,
    data,
    message
  }
}

export function errorResponse(error: string, message?: string): ErrorResponse {
  return {
    success: false,
    error,
    message: message || error
  }
}

export function paginatedResponse<T = any>(
  data: T[],
  pagination: PaginationInfo,
  message?: string
): PaginatedResponse<T> {
  return {
    success: true,
    data,
    pagination,
    message
  }
}

export function validationErrorResponse(errors: Record<string, string[]> | string, message?: string): ErrorResponse {
  if (typeof errors === 'string') {
    return {
      success: false,
      error: 'VALIDATION_ERROR',
      message: errors || '数据验证失败'
    }
  }
  
  return {
    success: false,
    error: 'VALIDATION_ERROR',
    message: message || '数据验证失败',
    ...errors
  }
}